#include "MainState.h"
#include "Game.h"
#include <assert.h>

bool MainState::Init()
{
	TheDevice->setEventReceiver(&m_eReceiver);
	IGUISkin* skin = TheEngine::Instance()->GetGUI()->getSkin();
	IGUIFont* font = TheEngine::Instance()->GetGUI()->getFont("Resources/fontcourier.bmp");
	if (font)
	{skin->setFont(font);}

	IGUIButton* button;
	IGUIScrollBar* scroll;
	dimension2d<u32> dims = TheVideo->getScreenSize();
	float x = (dims.Width/640);
	float y = (dims.Height/480);
	int set = 100;

	m_pMainBoard = new MainBoard(x,y);
	for (u32 i=0; i<EGDC_COUNT ; ++i)
	{
		SColor col = TheEngine::Instance()->GetGUI()->getSkin()->getColor((EGUI_DEFAULT_COLOR)i);
		col.setAlpha(150);
		TheEngine::Instance()->GetGUI()->getSkin()->setColor((EGUI_DEFAULT_COLOR)i, col);
	}

	return true;
}

bool MainState::HandleEvents(const SEvent& event)
{
	return m_pMainBoard->EventHandler(event);
}
void MainState::Update()
{		
	m_pMainBoard->Update();
	TheAudio::Instance()->Update();

	if(!TheDevice->run())
	{
		assert("IrrLicht Error!");
		TheGame::Instance()->Quit();
	}
}
void MainState::Draw()
{

	//draw loop
	//if this window is active
	if (TheDevice->isWindowActive())
	{
		TheEngine::Instance()->Draw();
	}
	else // if the window is not active, don't draw
	{
		TheDevice->yield();
	}

}
void MainState::Cleanup()
{
	m_pMainBoard->Cleanup();
}